1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 import java.lang.reflect.Method;
32 import java.util.HashSet;
33 import java.util.Set;
34
35
36
37
38
39 public class NewNamesFormat {
40 public static void main(String[] args) throws Exception {
41 checkRes("sun.security.util.Resources");
42 checkRes("sun.security.util.AuthResources");
43 checkRes("sun.security.tools.JarSignerResources");
44 }
45
46 private static void checkRes(String resName) throws Exception {
47 System.out.println("Checking " + resName + "...");
48 Class clazz = Class.forName(resName);
49 Method m = clazz.getMethod("getContents");
50 Object[][] contents = (Object[][])m.invoke(clazz.newInstance());
51 Set<String> keys = new HashSet<String>();
52 for (Object[] pair: contents) {
53 String key = (String)pair[0];
54 if (keys.contains(key)) {
55 System.out.println("Found dup: " + key);
56 throw new Exception();
57 }
58 checkKey(key);
59 keys.add(key);
60 }
61 }
62
63 private static void checkKey(String key) throws Exception {
64 for (char c: key.toCharArray()) {
65 if (Character.isLetter(c) || Character.isDigit(c) ||
66 c == '{' || c == '}' || c == '.') {
67
68 } else {
69 System.out.println("Illegal char [" + c + "] in key: " + key);
70 throw new Exception();
71 }
72 }
73 }
74 }